package com.etl.dataflow.scheduler.admin.controller;


import com.etl.dataflow.common.response.R;
import com.etl.dataflow.scheduler.admin.entity.DataflowTaskStatistic;
import com.etl.dataflow.scheduler.admin.entity.request.PageRequest;
import com.etl.dataflow.scheduler.admin.service.DataflowTaskStatisticService;
import com.etl.dataflow.scheduler.admin.validation.Add;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

/**
 * <p>
 * 任务运行统计信息 前端控制器
 * </p>
 *
 * @author dx
 * @since 2022-04-24
 */
@RestController
@RequestMapping("/admin/task-statistic")
public class DataflowTaskStatisticController implements DefaultController {
    private final DataflowTaskStatisticService taskInfoService;

    public DataflowTaskStatisticController(DataflowTaskStatisticService taskInfoService) {
        this.taskInfoService = taskInfoService;
    }

    @PostMapping("/addOrUpdate")
    public R add(@RequestBody @Validated(Add.class) DataflowTaskStatistic datasource) {
        return successOrError(taskInfoService.saveOrUpdate(datasource));
    }

    @GetMapping("/remove")
    public R remove(@RequestParam @NotNull Long id) {
        return successOrError(taskInfoService.removeById(id));
    }

    @GetMapping("/find")
    public R find(@RequestParam @NotEmpty String id) {
        DataflowTaskStatistic datasource = taskInfoService.getById(id);
        return R.success().put("data", datasource);
    }

    @PostMapping("/paging")
    public R paging(@RequestBody @Validated PageRequest pageRequest) {
        return taskInfoService.page(pageRequest);
    }
}
